﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CenterSpace.NMath.Core;
using CenterSpace.NMath.Stats;
using CenterSpace.NMath.Matrix;
using SensorNetworkUI;

namespace WebAccess
{
    public class Mean :DescriptiveMethods
    {

        
        public override double Calculate(HashSet<SensorStructure> sensors)
        {
            double ret = 0;


            double[] vals = SetToArray(sensors);
            
            ret = StatsFunctions.Mean(vals);
            return ret;



        }



    }
    public class Mode : DescriptiveMethods
    {
        

        public override double Calculate(HashSet<SensorStructure> sensors)
        {
            double[] vals = SetToArray(sensors);
            return StatsFunctions.Mode(vals);


        }


    }

    public class Min : DescriptiveMethods
    {
        public override double Calculate(HashSet<SensorStructure> sensors)
        {
            double[] vals = SetToArray(sensors);
            return StatsFunctions.MinValue(vals);
        }
    }
    public class Max : DescriptiveMethods
    {
        public override double Calculate(HashSet<SensorStructure> sensors)
        {
            double[] vals = SetToArray(sensors);
            return StatsFunctions.MaxValue(vals);
            
        }
        
    }
    public class MeanDeviation : DescriptiveMethods
    {
        public override double Calculate(HashSet<SensorStructure> sensors)
        {

            double[] vals = SetToArray(sensors);
            return StatsFunctions.MeanDeviation(vals);
        }
    }
    public class SD : DescriptiveMethods
    {

        public override double Calculate(HashSet<SensorStructure> sensors)
        {
            double[] vals = SetToArray(sensors);
            return StatsFunctions.StandardDeviation(vals);
            
        }
    }
    public class Skewness : DescriptiveMethods
    {

        public override double Calculate(HashSet<SensorStructure> sensors)
        {
            double[] vals = SetToArray(sensors);
            
            return StatsFunctions.Skewness(vals);
        }

    }

    public class Median : DescriptiveMethods
    {

        public override double Calculate(HashSet<SensorStructure> sensors)
        {
            double[] vals = SetToArray(sensors);
            return StatsFunctions.Median(vals);
        }

    }
    
    
    public abstract class DescriptiveMethods : StatEngine
    {
        protected DescriptiveMethods(){
            
        }
        public  abstract  double Calculate(HashSet<SensorStructure> sensors);
        
        public static DescriptiveMethods GetInstance(String value)
        {
            switch (value)
            {
                case "Mean":
                    return new Mean();
                case "SD": 
                    return new SD();
                case "Skewness": 
                    return new Skewness();
                case "Min":
                    return new Min();
                case "Max":
                    return new Max();
                case "Mode":
                    return new Mode();
                case "MD":
                    return new MeanDeviation();
                
                
                default:
                    throw new NotImplementedException();


            }


        }


    }
}